import { baseRequestClient, requestClient } from '#/api/request';

export namespace AuthApi {
  /** 登录接口参数 */
  export interface LoginParams {
    userName?: string;
    passWord?: string;
    phoneNumber?: string;
  }

  /** 登录接口返回值 */
  export interface LoginResult {
    accessToken: string;
  }

  export interface RefreshTokenResult {
    data: string;
    status: number;
  }
}

/**
 * 登录
 */
export async function loginApi(data: AuthApi.LoginParams) {
  // return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
  return baseRequestClient.post<AuthApi.LoginResult>(
    '/ChargeSystem/user/login',
    data,
  );
}
// 获取账号权限
export async function getAccountPermissionApi() {
  return baseRequestClient.get('/ChargeSystem/menu/selectInfo');
}
// 获取导航栏菜单
export async function getNavMenuApi() {
  return baseRequestClient.get('/ChargeSystem/user/findPageTree');
}

/**
 * 刷新accessToken
 */
export async function refreshTokenApi() {
  return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh', {
    withCredentials: true,
  });
}

/**
 * 退出登录
 */
export async function logoutApi() {
  return baseRequestClient.post('/auth/logout', {
    withCredentials: true,
  });
}

/**
 * 获取用户权限码
 */
export async function getAccessCodesApi() {
  return requestClient.get<string[]>('/auth/codes');
}
/**
 * 获取人员权限列表
 */
export async function getFindVillage(
  pageNo: number,
  pageSize: number,
  query: any,
) {
  return baseRequestClient.post(`/ChargeSystem/person/findVillagePermissions`, {
    pageNo: pageNo,
    pageSize: pageSize,
    ...query,
  });
}
/**
 * 获取当前公司id
 *
 */
export async function getCurrentCompanyIdApi() {
  return baseRequestClient.post(`/ChargeSystem/selectCommonId`);
}
/**
 * 获取小区
 */
export async function getVillageListApi(id: string) {
  return baseRequestClient.post(`/ChargeSystem/findVillageTree?id=${id}`);
}
/**
 * 新增人员权限
 */
export async function getInsert(data: any) {
  return baseRequestClient.post(
    `/ChargeSystem/person/insertVillagePermissions`,
    data,
  );
}
/**
 * 页面权限搜索
 */
export async function getSearch(data: any) {
  return baseRequestClient.post(`/ChargeSystem/menu/findPagePermission`, data);
}
/**
 * 修改页面权限
 */
export async function getUpdate(data: any) {
  return baseRequestClient.post(`/ChargeSystem/menu/updatePagePor`, data);
}
/**
 * 按钮权限
 */
export async function getButtonAuth(data: any) {
  return baseRequestClient.post(`/ChargeSystem/menu/selectPageTree`, data);
}
/**
 * 获取账户按钮的权限
 *
 */
export async function getAccountButtonAuth(data: any) {
  return baseRequestClient.get(`/ChargeSystem/menu/findBtnInfo`, {
    params: {
      ...data
    },
  });
}
/**
 * 修改账户按钮权限
 */
export async function getUpdateAccountButtonAuth(data: any) {
  return baseRequestClient.post(`/ChargeSystem/menu/updateBtn`, data);
}
/**
 * 
 *获取账户列表
 */
export async function getAccountList(data: any) {
  return baseRequestClient.post(`/ChargeSystem/user/findUserInfo`, data);
}
/**
 * 新增账户
 */
export async function getAddAccount(data: any) {
  return baseRequestClient.post(`/ChargeSystem/user/addUserInfo`, data);
}
/**
 * 修改账户
 */
export async function getUpdateAccount(data: any) {
  return baseRequestClient.post(`/ChargeSystem/user/updateUserInfo`, data);
}
/**
 * 删除账户
 */
export async function getDeleteAccount(data: any) {
  return baseRequestClient.post(`/ChargeSystem/user/deleteByUser?id=${data}`);
}
/**
 * 重置密码
 */
export async function getResetPassword(data: any) {
  return baseRequestClient.post(`/ChargeSystem/user/updatePassword`, data);
}
